#pragma once

#include <QWidget>
#include <QDateTime>
#include "QMainWindow.h"
#include "qcustomplot.h"
#include "UiCommon.h"

class TextLabel
{
public:
    void create(QCustomPlot *plot);    
    double value();

    void setLabel(double x, double y);
    bool isVisible();
    void show();
    void hide();    

protected:
    QCPItemText *label;
    QCPItemLine *arrow;
    QCustomPlot *m_plot;
    double xvalue;
};


class PlotWidget : public QMainWindow
{
    Q_OBJECT

public:
    PlotWidget(QWidget *w,int type);

    void setRealTime(bool flag);    
    void clear();

    void addData(QDateTime time, float data);
	void setData(QDateTime cur,const QVector<float> &y);
    void setTrans(double a);
    QVector<double> getGap();

signals:
    void sigFrameSelect(int index);

protected slots:
    void onMousePress(QMouseEvent *event);
    void onMouseRelese(QMouseEvent *event);

    void onActionDrag();
    void onActionSel();
    void onActionFit();
    void onActionGap();

protected:	
    void createToolBar();
    void updateDragMode();
    void updatePlot();

    int m_select;
    QVector<QDateTime> m_times;    

    QVector<double> m_x;
    QVector<double> m_y;
    QDateTime m_time;    

    TextLabel m_label[2];    
    int m_labelIndex;

    QAction *actDrag;
    QCustomPlot *m_plot;
    QCPGraph *m_graph;    
    QPoint m_downPos;
    bool m_down;
    double m_a;

    int m_plotType;
    int m_real;
};